package chapter4.namedJDBC;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class NamedJDBCTest {
	
    public static void main( String[] args ){
		NamedJDBCTest test = new NamedJDBCTest();
    	UserAction userAction = test.getController();
    	//test.testAdd(userAction);
    	//test.addUser(userAction);
    	test.testFindMapAll(userAction);

    }
    public UserAction getController(){
    	ApplicationContext context = 
        		new ClassPathXmlApplicationContext("chapter4_xml_bean.xml");
    	UserAction userAction = (UserAction) context.getBean("userAction");
    	return userAction;
    }
    
    public void testAdd(UserAction userAction){
   	
		Map<String,Object> paramMap=new HashMap<String,Object>();
		paramMap.put("id", 1);
		paramMap.put("age", "20");
		paramMap.put("name", "npjt1");
		paramMap.put("sex", "女");
		userAction.add(paramMap);
    }
    public void addUser(UserAction userAction){
    	User user  =new User();
    	user.setId(8);
    	user.setName("npjt2");
    	user.setAge(20);
    	userAction.addUser(user);
    }    
    public void testFindMapAll(UserAction userAction){
    	System.out.println("查询结果：");
    	Map<String,Object> paramMap=new HashMap<String,Object>();
    	List<Map<String,Object>> users  = userAction.findAllMap(paramMap);
    	for(Map<String,Object> user:users){
        	System.out.println("id："+user.get("id")
        	+",name:"+user.get("name")
        	+",age:"+user.get("age"));
    	}
    }
}
